<?
/**
 * Copyright 2008 Melange.
 *
 * This file is part of Melange CMS
 *
 * @package cms
 *
 */


/**
 * Requirements
 */
require_once("mvc/action/ActionForm.php");
require_once("mvc/action/ActionMessage.php");
require_once("mvc/action/ActionMessages.php");
require_once("cms/menu/om/Menu.php");



/**
 * BaseMenuForm Class
 *
 * @category    Melange CMS
 * @package     cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 */
class BaseMenuForm extends ActionForm {


    // ----------------------------------------------------- Instance Variables


    /**
     * menu
     *
     * @var Menu 
     */
    protected $menu;


    // ----------------------------------------------------------- Constructors


    /**
     * Construct new BaseMenuForm
     */
    public function __construct() {
        $this->menu = new Menu();
    }


    // ------------------------------------------------------------- Properties


    /**
     * Get Menu
     *
     * @return Menu 
     */
    public function getMenu() {
        return $this->menu;
    }


    /**
     * Set Menu
     *
     * @param Menu  menu
     */
    public function setMenu(Menu $menu) {
        $this->menu = $menu;
    }


    // --------------------------------------------------------- Public Methods


    /**
     * Validate this form
     *
     * @return array $errors
     */
    public function validate() {

        $errors = new ActionMessages();

        if(is_null($this->getMenu()->getName()) || strlen($this->getMenu()->getName()) == 0)
            $errors->add("menu->name",
                new ActionMessage("errors.required", true, new ActionMessage("prompt.name", true)));


        if(!is_null($this->getMenu()->getName()) && strlen($this->getMenu()->getName()) > 0 && strlen($this->getMenu()->getName()) > 255)
            $errors->add("menu->name",
                new ActionMessage("errors.maxlength", true, array(
                    new ActionMessage("prompt.name", true),
                    new ActionMessage("255", false))));


        return $errors;
    }

}
?>